package com.adcc.ags.agent;

import com.adcc.ags.agent.healthcheck.CPUHealthCheck;
import com.adcc.ags.agent.healthcheck.DiskHealthCheck;
import com.adcc.ags.agent.healthcheck.MemoryHealthCheck;
import com.adcc.ags.agent.healthcheck.NetworkHealthCheck;
import com.adcc.ags.agent.resouce.NetWorkCheckResource;
import com.adcc.utility.log.Log;
import io.dropwizard.Application;
import io.dropwizard.setup.Environment;

public class App extends Application<AppConfiguration> {
    @Override
    public void run(AppConfiguration configuration, Environment environment) throws Exception {
        try {
            environment.jersey().register(new NetWorkCheckResource(configuration.getPing(),configuration.getTracert()));
            environment.healthChecks().register("CPU",new CPUHealthCheck());
            environment.healthChecks().register("Disk",new DiskHealthCheck());
            environment.healthChecks().register("Memory",new MemoryHealthCheck());
            environment.healthChecks().register("Network",new NetworkHealthCheck(configuration.getNetworkDevice()));
        } catch (Exception ex) {
            Log.error(App.class.getName(),"run() error", ex);
        }
    }
    public static void main(String[] args) throws Exception {
        String[] paras = (args == null || args.length != 2) ?
                new String[]{"server","./Agent/conf/conf.yml"} : args;
        App app = new App();
        app.run(paras);
    }

}
